package com.eigaland.change_machine.business.movielist

import com.eigaland.change_machine.BuildConfig
import com.eigaland.change_machine.business.network.RetrofitClient
import com.eigaland.change_machine.displaymodel.MovieListItemDisplayModel
import com.eigaland.change_machine.util.UserManager
import com.eigland.eigaland_lib.base.BaseRepository
import com.eigland.eigaland_lib.network.MovieService

public class MovieListFragmentRepository : BaseRepository(){

   suspend fun getMovieList():MovieListItemDisplayModel{
        var displayModel = MovieListItemDisplayModel()

        var list = ArrayList<MovieListItemVM>()
        var result =
            UserManager.cinemaId?.let {
                RetrofitClient.getService(MovieService::class.java,BuildConfig.domain).movieShowingList(
                    it
                ).await()
            }
        result?.success.let {
            it?.content?.forEach { it ->
                var item = MovieListItemVM()
                item.movieId = it.movie.uuid
                item.movieName = it.movie.name
                item.imageUrl = it.movie.posterUrl
                list.add(item)

            }
        }


       displayModel.movieItems = list

        return displayModel
    }

    suspend fun takeTicket(ticket:String):MovieListItemDisplayModel{
        var displayModel = MovieListItemDisplayModel()

        var result = RetrofitClient.getService(MovieService::class.java,BuildConfig.domain).takeTicketByNo(ticket).await()

        result?.success.let{

        }
        result?.error?.let {
            displayModel.errorMsg = it.message
        }

        return displayModel
    }

}